/* eslint-disable */
import React from "react";
import {Input, Button, message} from "antd";
import axios from "axios";
import qs from "qs";


import "./../../view/Login/Login.less";
import bgimg from "../../assets/images/bgimg.png";
import logo from "../../assets/images/4-logo_2@3x.png";


class Login extends React.Component {
	constructor(props) {
		//创建组件时必须执行的方法，构造方法
		super();
		// console.log(props);
		// this.name = "tom"
		this.state = {
			Account : "",
			Password: "",
		};
	}

	componentWillMount() {
		let UserInfo = sessionStorage.getItem("UserInfo");
		if (UserInfo) {
			console.log("已经登陆，跳转", UserInfo);
			this.props.history.push("/");
			// 已经登陆，跳转
		} else {
			console.log("没有登陆", UserInfo);
		}
	}

	handleSubmit = (e) => {
		e.preventDefault();
		// console.log(this.state);
		let {Account, Password} = this.state;
		if (!Account && !Password) {
			message.error("账号密码错误");
			return false;
		}
		sessionStorage.setItem("UserInfo", JSON.stringify(this.state));
		this.props.history.push("/");
		// axios.post("", qs.parse(this.state)).then(e => {
		// 	console.log(e);
		// });
		// this.props.form.validateFields((err, values) => {
		// 	if (!err) {
		// 		localStorage.setItem('user', JSON.stringify({'code':1111,uid:'1'}))
		// 		//window.location.href='http://gsr.501533.com/index.php?m=index&a=home#/main'
		// 		var href = "http://" + window.location.href.substr(7, window.location.href.length).substr(0, window.location.href.substr(7, window.location.href.length).indexOf("/"));
		// 		window.location.href = href + "/main";
		// 		// server.login(values)
		//
		// 	}
		// });
	};
	AccountInput = (type, e) => {
		if (type == "Password") {
			var data = {
				Password: e.target.value,
			};
		} else {
			var data = {
				Account: e.target.value,
			};
		}
		this.setState(data);

	};

	render() {
		return (
			<div className="login-wrap aaa">
				<div className="content d-flex ">
					<div className="left">
						<div className="logo">
							<img src={logo} height="50" alt=""/>
						</div>
						<div>
							<div>
								<Input className="w-250px" type="text" onChange={this.AccountInput.bind(this, "Account")} onPressEnter={this.handleSubmit.bind(this)} placeholder="Account"/>
							</div>
							<div className="mt-25px">
								<Input type="password" onChange={this.AccountInput.bind(this, "Password")} onPressEnter={this.handleSubmit.bind(this)} className="w-250px" placeholder="Password"/>
							</div>
							<div className="mt-40px"><Button onClick={this.handleSubmit} size="large" type="primary" shape="round" className="w-130px">LOGIN</Button></div>
						</div>
					</div>
					<div className="right">
						<img src={bgimg} className="w-100 h-100" alt=""/>
					</div>
				</div>
				<div className="icp"><a href="">沪ICP备2021010311号</a></div>
			</div>
		);
	}

	click() {
		// this.name ='List';
		// var obj={
		//   name:'Alan'
		// }
		this.setState({
			name: "6666",
		});
		// this.setState(obj)
		console.log("click...");
	}

}

export default Login;
